package com.llxy.web.controller.worker;
import com.llxy.common.annotation.Log;
import com.llxy.common.core.controller.BaseController;
import com.llxy.common.core.domain.AjaxResult;
import com.llxy.common.core.page.TableDataInfo;
import com.llxy.common.enums.BusinessType;
import com.llxy.worker.domain.Category;
import com.llxy.worker.domain.SupportWorker;
import com.llxy.worker.dto.SupportWorkerDTO;
import com.llxy.worker.service.CategoryService;
import com.llxy.worker.service.impl.CategoryServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* (t_category)表控制层
*
* @author 马瑞龙
*/
@RestController
@RequestMapping("/worker/category")
public class CategoryController extends BaseController {
    /**
    * 服务对象
    */
    @Autowired
    private CategoryService categoryService;

    /**
     * 获取分类列表
     */
    @PreAuthorize("@ss.hasPermi('worker:category:list')")
    @GetMapping("/list")
    @ApiOperation(httpMethod = "GET", value = "获取分类列表", notes = "获取分类列表")
    public TableDataInfo list(Category category)
    {
        startPage();
        List<Category> categoryList = categoryService.selectCategoryWorkerList(category);
        return getDataTable(categoryList);
    }

    /**
     * 分类列表
     */
    @PreAuthorize("@ss.hasPermi('worker:category:list')")
    @GetMapping("/allList")
    @ApiOperation(httpMethod = "GET", value = "获取列表", notes = "获取列表")
    public AjaxResult allList(Category category)
    {
        List<Category> categoryList = categoryService.selectCategoryWorkerList(category);
        return success(categoryList);
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('worker:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Integer id)
    {
        return success(categoryService.selectByPrimaryKey(id));
    }


    /**
     * 新增分类
     */
    @PreAuthorize("@ss.hasPermi('worker:category:add')")
    @Log(title = "分类管理", businessType = BusinessType.INSERT)
    @ApiOperation(httpMethod = "POST", value = "新增分类", notes = "新增分类")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Category category)
    {
        category.setCreateBy(getUsername());
        return toAjax(categoryService.insertSelective(category));
    }

    /**
     * 修改分类
     */
    @PreAuthorize("@ss.hasPermi('worker:category:edit')")
    @Log(title = "护工管理", businessType = BusinessType.UPDATE)
    @ApiOperation(httpMethod = "PUT", value = "修改分类", notes = "修改分类")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Category category)
    {
        category.setUpdateBy(getUsername());
        return toAjax(categoryService.updateByPrimaryKeySelective(category));
    }

    /**
     * 删除分类
     */
    @PreAuthorize("@ss.hasPermi('worker:support:remove')")
    @Log(title = "护工管理", businessType = BusinessType.DELETE)
    @ApiOperation(httpMethod = "DELETE", value = "删除分类", notes = "删除分类")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id)
    {
        return toAjax(categoryService.deleteByPrimaryKey(id));
    }


}
